/* 
 * File:   TBBFiltre.cpp
 * Author: amouro-m
 * 
 * Created on 31 mai 2010, 20:45
 */

#include "TBBFiltre.h"

#include "TBBCompute.h"
#include "Zone.h"

TBBFiltre::TBBFiltre(Computable* computable, FractalPrinter* fp, ResultPanel* result_panel):
tbb::filter(false),
_fp(fp),
_computable(computable),
_result_panel(result_panel),
_next_area(0)
{}

TBBFiltre::TBBFiltre(const TBBFiltre& tbb_filtre):
tbb::filter(false),
_computable(tbb_filtre._computable),
_result_panel(tbb_filtre._result_panel),
_fp(tbb_filtre._fp)
{}

TBBFiltre::~TBBFiltre() {}

void*
TBBFiltre::operator() (void*)
{
    int s_x = (_next_area % 2) * _fp->get_width() / 2;
    int e_x = (((_next_area) % 2) +1)  * _fp->get_width() / 2;
    int s_y = (_next_area / 2) * _fp->get_height() / 4;
    int e_y = (_next_area + 2) / 2  * _fp->get_height() / 4;
    _next_area++;

    if (_next_area == 9)
        return NULL;

    for (int i = s_x; i < e_x; ++i)
    {
        for (int j = s_y; j < e_y; ++j)
        {
            _computable->compute(_fp->get_area(), i, j);
        }
    }

    _fp->repaint();

    return (void*)_fp;
}